package com.yuan.controller;


import com.yuan.Result.Result;
import com.yuan.entity.Dept;
import com.yuan.service.IDeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 部门表 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-11-05
 */
@RestController
@RequestMapping
@Slf4j
public class DeptController {

    @Autowired
    private IDeptService deptService;

    @GetMapping("/depts")
    public Result getAllDepts() {
        log.info("获取部门列表");
        List<Dept> list = deptService.list();
        System.out.println(list);
        return Result.success(list);
    }

    @DeleteMapping("/depts/{id}")
    public Result deleteDept(@PathVariable Integer id) {
        deptService.removeById(id);
        return Result.success();
    }

    @PostMapping("/depts")
    public Result addDept(@RequestBody Dept dept) {
        deptService.save(dept);
        return Result.success();
    }


}
